package com.example.maple.ccsclient.utils;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * Created by maple on 2016/7/7.
 */
public class SharedPreferencesUtils {

	//所有有关GridView列数，默认设置4列


	//获取图片的列数
	public static int getPicColumn(Context context) {
		SharedPreferences preference = context.getSharedPreferences("", Context.MODE_PRIVATE);

		if (!preference.contains("picColumn")) {
			preference.edit().putInt("picColumn", 4);
		}
		return preference.getInt("picColumn", 4);
	}

	//获取文字的列数
	public static int getCharColumn(Context context) {

		SharedPreferences preference = context.getSharedPreferences("", Context.MODE_PRIVATE);

		if (!preference.contains("charColumn")) {
			preference.edit().putInt("charColumn", 4);
		}
		return preference.getInt("charColumn", 4);
	}

	//设置保存图片的透明度


	//设置图片列数
	public static void setPicColumn(Context context, int value) {
		if (0 == value) {
			value = 1;
		}
		SharedPreferences preference = context.getSharedPreferences("", Context.MODE_PRIVATE);
		SharedPreferences.Editor editor = preference.edit();
		editor.putInt("picColumn", value);
		editor.commit();
	}

	//设置文字列数

	public static void setCharColumn(Context context, int value) {
		if (0 == value) {
			value = 1;
		}
		SharedPreferences preference = context.getSharedPreferences("", Context.MODE_PRIVATE);
		SharedPreferences.Editor editor = preference.edit();
		editor.putInt("charColumn", value);
		editor.commit();

	}


	//设置首页存储，如果首次进入，手机无网络状态，就加载最后一次刷新的数据
	//格式  诗句1#诗句2#Json字符串
	public static void setFirstData(Context context, String data) {
		SharedPreferences preference = context.getSharedPreferences("", Context.MODE_PRIVATE);
		SharedPreferences.Editor editor = preference.edit();
		editor.putString("firstData", data);
		editor.commit();
	}


	public static String getFirstData(Context context) {

		SharedPreferences preference = context.getSharedPreferences("", Context.MODE_PRIVATE);
		return preference.getString("firstData", "");
	}

	//设置米字格开关
	public static void setIntersected(Context context,boolean isShow){
		SharedPreferences preference = context.getSharedPreferences("", Context.MODE_PRIVATE);
		SharedPreferences.Editor editor = preference.edit();
		editor.putBoolean("intersected", isShow);
		editor.commit();
	}

	public static boolean getIntersected(Context context){
		SharedPreferences preference = context.getSharedPreferences("", Context.MODE_PRIVATE);
		return preference.getBoolean("intersected", true);
	}
}
